package football_behaviour

import (
	"longmen/server/config/global"
	"longmen/server/internal/services/nami/services/sports/football"
	"longmen/server/pkg/db/mysql/models/models_sports"
)

type (
	RecentApiResponse struct {
		Code  int `json:"code"`
		Query struct {
			Total int    `json:"total"`
			Type  string `json:"type"`
			ID    int    `json:"id"`
			MinID int    `json:"min_id"`
			MaxID int    `json:"max_id"`
			Limit int    `json:"limit"`
		} `json:"query"`
		Results []Result `json:"results"`
	}
	Result struct {
		ID            int    `json:"id"`
		SeasonID      int    `json:"season_id"`
		CompetitionID int    `json:"competition_id"`
		HomeTeamID    int    `json:"home_team_id"`
		AwayTeamID    int    `json:"away_team_id"`
		StatusID      int    `json:"status_id"`
		MatchTime     int64  `json:"match_time"`
		Neutral       int    `json:"neutral"`
		Note          string `json:"note"`
		HomeScores    Scores `json:"home_scores"`
		AwayScores    Scores `json:"away_scores"`
		HomePosition  string `json:"home_position"`
		AwayPosition  string `json:"away_position"`
		Coverage      struct {
			Mlive        int `json:"mlive"`
			Intelligence int `json:"intelligence"`
			Lineup       int `json:"lineup"`
		} `json:"coverage"`
		VenueID   int    `json:"venue_id"`
		RefereeID int    `json:"referee_id"`
		RelatedID int    `json:"related_id"`
		AggScore  Scores `json:"agg_score"`
		Round     struct {
			StageID  int `json:"stage_id"`
			GroupNum int `json:"group_num"`
			RoundNum int `json:"round_num"`
		} `json:"round"`
		UpdatedAt   int `json:"updated_at"`
		Environment struct {
			Weather     int    `json:"weather"`
			Pressure    string `json:"pressure"`
			Temperature string `json:"temperature"`
			Wind        string `json:"wind"`
			Humidity    string `json:"humidity"`
		} `json:"environment,omitempty"`
	}
)

func (r RecentApiResponse) UpdateMatchInterFaces() []football.UpdateMatchInterface {
	a := make([]football.UpdateMatchInterface, 0)
	for _, record := range r.Results {
		a = append(a, record)
	}
	global.Log.Info("count : ", len(r.Results))
	return a
}

func (r Result) GetUpdate() models_sports.FootballMatch {
	return models_sports.FootballMatch{
		ID:            r.ID,
		SeasonID:      r.SeasonID,
		CompetitionID: r.CompetitionID,
		HomeTeamID:    r.HomeTeamID,
		AwayTeamID:    r.AwayTeamID,
		StatusID:      models_sports.FootBallMatchStatus(r.StatusID),
		MatchTime:     r.MatchTime,
		Neutral:       r.Neutral,
		Note:          r.Note,
		HomeScores:    r.HomeScores.String(),
		AwayScores:    r.AwayScores.String(),
		HomePosition:  r.HomePosition,
		AwayPosition:  r.AwayPosition,
		Mlive:         r.Coverage.Mlive,
		Intelligence:  r.Coverage.Intelligence,
		Lineup:        r.Coverage.Lineup,
		VenueID:       r.VenueID,
		RefereeID:     r.RefereeID,
		RelatedID:     r.RelatedID,
		AggScore:      r.AggScore.String(),
		UpdatedAt:     r.UpdatedAt,
	}
}
